﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;

namespace BCNPCObject.EXCEL
{
    public class cls_HDG_KHANG_LIENHE_Controller
    {
        #region   Atributes

        //private DataSet CMIS_Header = new CMISOutputParameter();
        private HDG_KHANG_LIENHE info;

        #endregion

        #region   Constructor

        public cls_HDG_KHANG_LIENHE_Controller()
        {
            info = new HDG_KHANG_LIENHE();
        }
        public cls_HDG_KHANG_LIENHE_Controller(HDG_KHANG_LIENHE Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public HDG_KHANG_LIENHE pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region Methods
        public bool insert_HDG_KHANG_LIENHE(ref Int64 id_lienhe,ref string maloi)
        {
            long _ID = CMIS2.DB.ExecuteCommand("Select SEQ_HDG_KHANG_LIENHE.NEXTVAL from dual");
            if (_ID == -1) return false;
            try
            {
                info.ID_LIENHE = Convert.ToInt64(_ID);
                HDG_KHANG_LIENHE objHDG_KHANG_LIENHE = new HDG_KHANG_LIENHE()
                {
                    MA_DVIQLY = info.MA_DVIQLY,
                    ID_LIENHE = info.ID_LIENHE,
                    MA_YCAU_KNAI = info.MA_YCAU_KNAI,
                    MA_KHANG = info.MA_KHANG,
                    STTU_UTIEN = info.STTU_UTIEN,
                    NGAY_HLUC = info.NGAY_HLUC,
                    TRANG_THAI = info.TRANG_THAI,
                    TEN_LIENLAC = info.TEN_LIENLAC,
                    DCHI_NHA = info.DCHI_NHA,
                    SO_CMT = info.SO_CMT,
                    NGAY_CAP = info.NGAY_CAP,
                    NOI_CAP = info.NOI_CAP,
                    SOGIAY_UQUYEN = info.SOGIAY_UQUYEN,
                    TEN_CQUAN = info.TEN_CQUAN,
                    CHUC_VU = info.CHUC_VU,
                    DCHI_CQUAN = info.DCHI_CQUAN,
                    DTHOAI_DD = info.DTHOAI_DD,
                    DTHOAI_CQ = info.DTHOAI_CQ,
                    DTHOAI_NR = info.DTHOAI_NR,
                    DTHOAI_KOGOI = info.DTHOAI_KOGOI,
                    FAX = info.FAX,
                    EMAIL = info.EMAIL,
                    EMAIL2 = info.EMAIL2,
                    EMAIL_KOGUI = info.EMAIL_KOGUI,
                    WEBSITE = info.WEBSITE,
                    GIOI_TINH = info.GIOI_TINH,
                    NGAY_SINH = info.NGAY_SINH,
                    NGHE_NGHIEP = info.NGHE_NGHIEP,
                    TRINH_DO = info.TRINH_DO,
                    MA_CNANG = info.MA_CNANG,
                    NGAY_TAO = info.NGAY_TAO,
                    NGUOI_TAO = info.NGUOI_TAO,
                    NGAY_SUA = info.NGAY_SUA,
                    NGUOI_SUA = info.NGUOI_SUA
                };
                CMIS2.DB.HDG_KHANG_LIENHE.InsertOnSubmit(info);
                CMIS2.DB.SubmitChanges();
                id_lienhe = _ID;
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB();
                return false;
            }
        }
        public bool delete_HDG_KHANG_LIENHE(DataTable dt, ref string maloi)
        {
            try
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        var query = from p in CMIS2.DB.HDG_KHANG_LIENHE
                                    where (p.MA_DVIQLY == dt.Rows[i]["MA_DVIQLY"].ToString() && p.MA_KHANG == dt.Rows[i]["MA_KHANG"].ToString() && p.ID_LIENHE == Convert.ToInt64(dt.Rows[i]["ID_LIENHE"]))
                                    select p;
                        if (query != null && query.Count() > 0)
                        {
                            CMIS2.DB.HDG_KHANG_LIENHE.DeleteAllOnSubmit(query.ToList());
                            CMIS2.DB.SubmitChanges();
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB(); return false;
            }
        }
        #endregion
    }
}
